////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// This file is a part of PMCG project. PMCG is the acronym of Physical       //
// Methods in Computer Graphics.                                              //
//                                                                            //
// Classical algorithms in computer graphics use discrete objects in 3D space //
// like vectors, matrices, triangles, planes. Physical way use an  analytical //
// objects like function, scalar and vector fields. Physical way gives new    //
// look to classical algorithms and allows to overcome some difficulties of   //
// pure geometric methods.                                                    //
//                                                                            //
// Project site:                                                              //
//     http://code.google.com/p/pmcg/                                         //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <fstream>

#include "TriMesh.h"
#include "IOTriMesh.h"

using namespace std;

void ReadFromObj(const char * objFileName, TriMesh & mesh)
{
    ifstream in;

    in.open(objFileName, ifstream::in);
    if (! in.is_open())
        throw exception();

    char c;
    double x, y, z;
    int i0, i1, i2;

    while (! in.eof())
    {
        in >> c;

        if (c == 'v')
        {
            in >> x >> y >> z;
            mesh.m_vertices.push_back(Vector3D(x, y, z));
        }
        else
        {
            in >> i0 >> i1 >> i2;
            mesh.m_faces.push_back(TriMesh::Face(i0 - 1, i1 - 1, i2 - 1));
        }
    }

    in.close();
}

